{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Examples and Exercises from Think Stats, 2nd Edition\n",
    "\n",
    "http://thinkstats2.com\n",
    "\n",
    "Copyright 2016 Allen B. Downey\n",
    "\n",
    "MIT License: https://opensource.org/licenses/MIT\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from __future__ import print_function, division\n",
    "\n",
    "%matplotlib inline\n",
    "\n",
    "import numpy as np\n",
    "\n",
    "import nsfg\n",
    "import first"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Given a list of values, there are several ways to count the frequency of each value."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "t = [1, 2, 2, 3, 5]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can use a Python dictionary:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1: 1, 2: 2, 3: 1, 5: 1}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hist = {}\n",
    "for x in t:\n",
    "    hist[x] = hist.get(x, 0) + 1\n",
    "    \n",
    "hist"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can use a `Counter` (which is a dictionary with additional methods):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Counter({1: 1, 2: 2, 3: 1, 5: 1})"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from collections import Counter\n",
    "counter = Counter(t)\n",
    "counter"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Or you can use the `Hist` object provided by `thinkstats2`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Hist({1: 1, 2: 2, 3: 1, 5: 1})"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import thinkstats2\n",
    "hist = thinkstats2.Hist([1, 2, 2, 3, 5])\n",
    "hist"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Hist` provides `Freq`, which looks up the frequency of a value."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hist.Freq(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also use the bracket operator, which does the same thing."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hist[2]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If the value does not appear, it has frequency 0."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hist[4]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `Values` method returns the values:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys([1, 2, 3, 5])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hist.Values()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "So you can iterate the values and their frequencies like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 1\n",
      "2 2\n",
      "3 1\n",
      "5 1\n"
     ]
    }
   ],
   "source": [
    "for val in sorted(hist.Values()):\n",
    "    print(val, hist[val])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Or you can use the `Items` method:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 1\n",
      "2 2\n",
      "3 1\n",
      "5 1\n"
     ]
    }
   ],
   "source": [
    "for val, freq in hist.Items():\n",
    "     print(val, freq)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`thinkplot` is a wrapper for `matplotlib` that provides functions that work with the objects in `thinkstats2`.\n",
    "\n",
    "For example `Hist` plots the values and their frequencies as a bar graph.\n",
    "\n",
    "`Config` takes parameters that label the x and y axes, among other things."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYwAAAEKCAYAAAAB0GKPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAFdlJREFUeJzt3XuwZWV95vHvkwbUKFG0j8rQNI01aIlGUU5hHKoUJoqNMYIJGZuogxZOTzngJZeZgeiIg5lUTGp0SiHBTuygGaUTL2TaDIIdQRmDKKexBRtC6CAJZ5qZbm1ECJak8Td/7NVT28O5vH1Zex/6fD9Vu3qt933X2r9dVPGcdXtXqgpJkhbyU+MuQJL02GBgSJKaGBiSpCYGhiSpiYEhSWpiYEiSmhgYkqQmBoYkqYmB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GRVfW7c9YxDVX0f+DKDKfsPZicDr+3O5W8A/mWS/z7ekkanqrZ3/+4AruQgmmnbwFDvugu/HwNur6oPjrueUUoykeQp3fITgFcAfzPeqvpVVRdW1YqqWsVg9oZrq+qNYy5rJJI8sbuxgyRPBE4DDpo7Ig2MEUtyBfA14DlJppOcO+6aRuBk4E0M/tLc0n1ePe6iRuRI4LoktzCYX21TVS2p20yXmGcAX03yLQbz3/3Pqrp6zDUdMN5WK0lq4hGGJKmJgSFJamJgSJKaGBiSpCYGhiSpiYEh9SzJgwuPkhY/A0OS1MTAkPZSkg8k+XdD6+9LclGSLyW5uXsXwhmzbHfK8LshklyS5M3d8olJvtJNWHdNNyW8tKgYGNLe2wC8fmj9XwF/Aryum3TuVOC/dlOiLKibZ+sjwFlVdSKwHvgvB7Zkaf8dMu4CpMeaqvpmkqcn+WfABHAfcC/woW5m0h8zeN/HM4D/07DL5wDPBzZ1GbOs25+0qBgY0r75DHAW8EwGRxxvYBAeJ1bVP3UztT5+xja7+cmj+j39AbZW1Ut7rVjaT56SkvbNBgYzsZ7FIDyezOAdEP+U5FTgmFm2+Xvg+CSPS/Jk4Oe79juAiSQvhcEpqiTP6/0XSHvJIwxpH1TV1m4a6/9dVfcm+STw+SRTwBZmmcK8qu5J8ufALcCdwDe79oeTnAV8uAuSQxi8sW7riH6O1MTZaiVJTTwlJUlqYmBIkpoYGJKkJgaGJKmJgSFJamJgSJKaGBiSpCYGhiSpyf8DWViKI8ZxllAAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import thinkplot\n",
    "thinkplot.Hist(hist)\n",
    "thinkplot.Config(xlabel='value', ylabel='frequency')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As an example, I'll replicate some of the figures from the book.\n",
    "\n",
    "First, I'll load the data from the pregnancy file and select the records for live births."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "preg = nsfg.ReadFemPreg()\n",
    "live = preg[preg.outcome == 1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here's the histogram of birth weights in pounds.  Notice that `Hist` works with anything iterable, including a Pandas Series.  The `label` attribute appears in the legend when you plot the `Hist`. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEKCAYAAAAFJbKyAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAHWBJREFUeJzt3X+cVXW97/HX2+HHaGAioBeBGlQ0DZVwFBL1+uNYaJ7I1MJTSF070zXtx6m8aXY1O3ov99Yp61gWKkc8KRw0KzRNyTDkHOKHiAiSx0kRJrgyihhGktDn/rG+g9thz8xew+zZe+D9fDz2Y6/92Wut/dkDM++9fuzvUkRgZmZWqn0q3YCZmfUsDg4zM8vFwWFmZrk4OMzMLBcHh5mZ5eLgMDOzXBwcZmaWi4PDzMxycXCYmVkuvSrdQDkMGjQo6urqKt2GmVmP8vjjj78UEYM7mm+PDI66ujqWLl1a6TbMzHoUSS+UMp93VZmZWS4ODjMzy8XBYWZmueyRxzjMrOd54403aGpq4vXXX690K3u82tpahg0bRu/evTu1vIPDzKpCU1MT/fv3p66uDkmVbmePFRG8/PLLNDU1MWLEiE6tw7uqzKwqvP766wwcONChUWaSGDhw4G5t2Tk4zKxqODS6x+7+nB0cZmaWS9mOcUiqBeYDfdPr3BMR10oaAcwCDgSWAZMj4i+S+gJ3AMcDLwMfjYg1aV1XAZcAO4DPRcRD5erbzKrD5dfP7NL13fS1i7p0fXuzch4c3wacERGvSeoNLJD0IPBF4DsRMU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1EfHvafrHwMlkWwXPR8R/pvqM1HtHfhER2yLiJbKBCg9O7/enEbE1st1jhWOxrSAbouXjZKPPtthINpKv7SV6VboBs1JFxMK022Vwkaf/1MHi2wqmd1D8//5jZFd3fAP4FdlV02rIPtXvA2yOiNHtvEZHQ1KX0kNr2yXtExEt1zNpPUZQdPC623lzl3TrS9C21U9b4xB9gCyQPgj8T0nvToFbC/y5nR5sD+MtDusx0jGFGrLdKu3ZQjbYXV7zgS8ACyOiGRgIvAtYlT59Py/pwtSLJB1XuHBEvAJskTQulUq95OsbyobFL+YZsotOtXiH3rw2+kXAArLdeHWSDk/1ycBv0vQast1PAOeX0Mt84DxJ+0rqD/wtgKR9yHatzSO7MNcBQL+0zBFku+hsL+HgsGrXcuB4OfBvZCN47uhgmRVkn9SfLDg4XopFZLtr5hesZ0VEtHwC/xhwiaQngVUUv2zwJcA0SQvJtgReLeF1pwEr2jg4/guyYzYtVgNTlI3oeyDZhaheBz5JthvtKbLrKrSMDHsd8F1Jj5FtVbQrsksQ/xvZcaWfkG2FQRbYP07rfwL4Trx5qd3TU5+2l/DouGZdSFK/iHgtTV8JDImIz+/G+oYAd0TEWcouC3x/RIzqkma7gKSDgbsi4sxK92Ldx8c4zLrWByRdRfa79QLZ2VSdFhEbJN1SqS8AluAdwJcq3YR1L29xmJlZLj7GYWZmuTg4zMwsFweHmZnl4uAwM7NcHBxmZpaLg8PMzHL5/9Sesj4iouyOAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "hist = thinkstats2.Hist(live.birthwgt_lb, label='birthwgt_lb')\n",
    "thinkplot.Hist(hist)\n",
    "thinkplot.Config(xlabel='Birth weight (pounds)', ylabel='Count')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Before plotting the ages, I'll apply `floor` to round down:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "ages = np.floor(live.agepreg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEKCAYAAAAIO8L1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAGAlJREFUeJzt3X+w1fV95/HnO4qCxogougq60A0aTaJoLog1kyA4RKVTcBJiYmpIhg3pRFNjOmmMu5lqtRPTcWvqJqMlakVjE63GxbomraKYWUdEUGuNmEhdhbtaofg7Sgz43j/O5+rx8r33HvB+7zkXno+ZM+f7/ZzPOed9v8O9Lz6f76/ITCRJ6u097S5AktSZDAhJUiUDQpJUyYCQJFUyICRJlQwISVIlA0KSVMmAkCRVMiAkSZV2bXcB78Z+++2XEyZMaHcZkjSsrFq16j8yc+xA/YZ1QEyYMIGVK1e2uwxJGlYi4ulW+jnFJEmqZEBIkioZEJKkSsN6H4Skncfvfvc7uru72bRpU7tLGTZGjhzJ+PHjGTFixHa934CQNCx0d3ez1157MWHCBCKi3eV0vMxk48aNdHd3M3HixO36DKeYJA0LmzZtYt999zUcWhQR7Lvvvu9qxGVASBo2DIdt8263lwEhSarkPghJw9JZF/14UD/v+//9s4P6eTsCA0JtMdAvt7+s2tlt2bKFXXbZpa01OMUkSdtg7ty5fOQjH+GDH/wgixYtAuCqq67i0EMPZfr06XzpS1/irLPOAmDDhg188pOfZMqUKUyZMoV7770XgPPPP58zzjiDGTNmMGnSJH74wx8CsGzZMk444QROP/10PvzhDwPwox/9iKlTpzJ58mS+/OUvs2XLln6/czA5glAt+hshODrQcHb11VczZswYXn/9daZMmcLs2bO58MILefDBB9lrr72YMWMGRx11FABnn30255xzDh/96EdZu3Ytn/jEJ1i9ejUAj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bESMLsujgBNp7De5G/hU6dYR2xb6rPfxpv8oBI05/bZv38z8VmaOz8wJNC7zc1dmfo4O3bZ91PtHg71tO+pM6qESET8GpgP7RUQ38OfAxcCNEbEAWAvMa1+F79RHvdPLIWwJPAV8uW0FvtPxwBnAv5a5Z4Dz6Mzt21etn+3QbXsgsDgaN9d6D3BjZt4WEY8BP4mIi4CHaIReJ+ir3rsiYiyNKZyHgT9uZ5ED+CaduW37cv1gblvPpJYkVXKKSZJUyYCQJFUyICRJlQwISVIlA0KSVMmAkCRVMiCkNijnBkgdzYCQBhARF/bcK6Ks/2VE/ElEfCMiHigXRrug6fX/FRGryj0QFja1vxoRfxER9wPHRcTFEfFYef8lQ/xjSQPyRDlpAOVKrz/NzGMi4j3AEzTOuJ5J4yzroHEpkb/KzF9ExJjMfL5cXuIB4OOZuTEiEjgtM2+MiDHAfcAHMjMjYnS5XpHUMXbKS21I2yIzn4qIjRFxNHAAjUsuTAFmlWWA9wKTgF8AfxIRp5b2g0v7RmALjQsDArwMbAKujIj/Ddw2FD+LtC0MCKk1VwJfAP4TcDWN0cN3MvNvmztFxHQaF6U7LjNfi4hlwMjy8qbM3AKQmZsjYmr5nM8AZ9G4gqjUMQwIqTW3AH9B465op9O4XemFEXF9Zr4aEeOA3wF7Ay+UcPgAjctxb6Xcg2KPzLw9IpYDa4bkp5C2gQEhtSAz34iIu2ncYWwL8M8RcThwX+PKyrwK/BHwc+CPI+IR4FfA8j4+ci9gSUSMpLEP45y6fwZpW7mTWmpB2Tn9IDAvM59odz3SUPAwV2kAEXEEjSmgpYaDdiaOICRJlRxBSJIqGRCSpEoGhCSpkgEhSapkQEiSKhkQkqRK/x/uHLXxCvUFxQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "hist = thinkstats2.Hist(ages, label='agepreg')\n",
    "thinkplot.Hist(hist)\n",
    "thinkplot.Config(xlabel='years', ylabel='Count')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As an exercise, plot the histogram of pregnancy lengths (column `prglngth`)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Hist` provides smallest, which select the lowest values and their frequencies."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10.0 2\n",
      "11.0 1\n",
      "12.0 1\n",
      "13.0 14\n",
      "14.0 43\n",
      "15.0 128\n",
      "16.0 242\n",
      "17.0 398\n",
      "18.0 546\n",
      "19.0 559\n"
     ]
    }
   ],
   "source": [
    "for weeks, freq in hist.Smallest(10):\n",
    "    print(weeks, freq)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use `Largest` to display the longest pregnancy lengths."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From live births, we can select first babies and others using `birthord`, then compute histograms of pregnancy length for the two groups."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "firsts = live[live.birthord == 1]\n",
    "others = live[live.birthord != 1]\n",
    "\n",
    "first_hist = thinkstats2.Hist(firsts.prglngth, label='first')\n",
    "other_hist = thinkstats2.Hist(others.prglngth, label='other')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can use `width` and `align` to plot two histograms side-by-side."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEKCAYAAAAFJbKyAAAABHNCSVQICAgIf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ifWpC8IjP/ApwM/J+I+Cm1kHld/QIz82Jqu73+ldrd2m4rdwNcRO3mPVLHeXVcSVIlbnFIkioxOCRJlRgckqRKDA5JUiUGhySpEoNDklSJwSFJqsTgkCRV8v8B9Up3XC4FdlUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "width = 0.45\n",
    "thinkplot.PrePlot(2)\n",
    "thinkplot.Hist(first_hist, align='right', width=width)\n",
    "thinkplot.Hist(other_hist, align='left', width=width)\n",
    "thinkplot.Config(xlabel='weeks', ylabel='Count', xlim=[27, 46])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Series` provides methods to compute summary statistics:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "mean = live.prglngth.mean()\n",
    "var = live.prglngth.var()\n",
    "std = live.prglngth.std()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here are the mean and standard deviation:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(38.56055968517709, 2.702343810070587)"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mean, std"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As an exercise, confirm that `std` is the square root of `var`:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here's are the mean pregnancy lengths for first babies and others:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(38.60095173351461, 38.52291446673706)"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "firsts.prglngth.mean(), others.prglngth.mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And here's the difference (in weeks):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.07803726677754952"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "firsts.prglngth.mean() - others.prglngth.mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This functon computes the Cohen effect size, which is the difference in means expressed in number of standard deviations:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "def CohenEffectSize(group1, group2):\n",
    "    \"\"\"Computes Cohen's effect size for two groups.\n",
    "    \n",
    "    group1: Series or DataFrame\n",
    "    group2: Series or DataFrame\n",
    "    \n",
    "    returns: float if the arguments are Series;\n",
    "             Series if the arguments are DataFrames\n",
    "    \"\"\"\n",
    "    diff = group1.mean() - group2.mean()\n",
    "\n",
    "    var1 = group1.var()\n",
    "    var2 = group2.var()\n",
    "    n1, n2 = len(group1), len(group2)\n",
    "\n",
    "    pooled_var = (n1 * var1 + n2 * var2) / (n1 + n2)\n",
    "    d = diff / np.sqrt(pooled_var)\n",
    "    return d"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Compute the Cohen effect size for the difference in pregnancy length for first babies and others."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Exercises"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using the variable `totalwgt_lb`, investigate whether first babies are lighter or heavier than others. \n",
    "\n",
    "Compute Cohen’s effect size to quantify the difference between the groups.  How does it compare to the difference in pregnancy length?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For the next few exercises, we'll load the respondent file:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "resp = nsfg.ReadFemResp()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Make a histogram of <tt>totincr</tt> the total income for the respondent's family.  To interpret the codes see the [codebook](http://www.icpsr.umich.edu/nsfg6/Controller?displayPage=labelDetails&fileCode=FEM&section=R&subSec=7876&srtLabel=607543)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Make a histogram of <tt>age_r</tt>, the respondent's age at the time of interview."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Make a histogram of <tt>numfmhh</tt>, the number of people in the respondent's household."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Make a histogram of <tt>parity</tt>, the number of children borne by the respondent.  How would you describe this distribution?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use Hist.Largest to find the largest values of <tt>parity</tt>."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's investigate whether people with higher income have higher parity.  Keep in mind that in this study, we are observing different people at different times during their lives, so this data is not the best choice for answering this question.  But for now let's take it at face value.\n",
    "\n",
    "Use <tt>totincr</tt> to select the respondents with the highest income (level 14).  Plot the histogram of <tt>parity</tt> for just the high income respondents."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Find the largest parities for high income respondents."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Compare the mean <tt>parity</tt> for high income respondents and others."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Compute the Cohen effect size for this difference.  How does it compare with the difference in pregnancy length for first babies and others?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Solution goes here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
